import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Test {


    /**
     *  获取请求token
     * @throws Exception
     */
    public static void getToken() throws Exception{
        Map<String,String> param=new HashMap<String,String>();
        param.put("client_id","xxxxxxxxx"); //你时习知应用的clientid
        param.put("client_secret","xxxxxxxxxxxxxxxxxx"); //你时习知应用的secret
        String contnet = HttpUtil.doPost("https://open.shixizhi.huawei.com/api/token", param);
        System.out.println(contnet);
    }

    /**
     * 请求参数(form-data/x-www-form-urlencoded)的样例
     * @throws Exception
     */
    public static void testGetPost() throws Exception{
        Map<String,String> param=new HashMap<String,String>();
        param.put("method","klt.school.info.get");
        param.put("version","1.0");
        param.put("access_token","xxxxxxxxxxxxxxxxxx");  //getToken接口
        String contnet = HttpUtil.doPost("https://open.shixizhi.huawei.com/api/router", param);
        System.out.println(contnet);
    }

    /**
     * body&json 请求样例
     * @throws Exception
     */
    public static void testGetPostBody() throws Exception{
        Map<String,String> param=new HashMap<String,String>();
        param.put("method","klt.school.dept.create");
        param.put("version","1.0");
        param.put("access_token","5578ac54-2e5d-4058-9134-a96abb16bd8b");

        Map<String,String> body=new HashMap<String,String>();
        body.put("dept_name","testdeptname");
        body.put("parent_dept_id","1");

        String contnet = HttpUtil.doPost("https://open.shixizhi.huawei.com/api/router", param,JSONObject.toJSONString(body));
        System.out.println(contnet);
    }


    public static void main(String[] args)throws Exception{
        testGetPostBody();

    }

}